package pers.sloera.nowcoder.ip;

import java.util.Scanner;
import java.util.regex.Pattern;

/**
 * class pers.sloera.nowcoder.ip
 * user sloera
 * date 2022/3/6
 * 86.67
 */
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        if (in.hasNextLine()) { // 注意 while 处理多个 case
            final String ip = in.nextLine();
            resolve(ip);
        }
        // 100#101#1#5
        // System.out.println(100*Math.pow(2, 24) + 101 * Math.pow(2, 16)+1 * Math.pow(2, 8) + 5);
    }

    private static int resolve(String ip) {
        boolean b = Pattern.compile("^[0-9#]*$").matcher(ip).find();
        if (!b) {
            System.out.println("invalid IP");
            return 0;
        }
        b = Pattern.compile(".*##+.*|0\\d+.*$").matcher(ip).find();
        if (!b) {
            System.out.println("invalid IP");
            return 0;
        }
        int result = 0;
        final String[] split;
        try {
            split = ip.split("#");
        } catch (Exception e) {
            System.out.println("invalid IP");
            return 0;
        }
        if (split.length != 4) {
            System.out.println("invalid IP");
            return 0;
        }
        for (int i = 0; i < split.length; i++) {
            try {
                final int number = Integer.parseInt(split[i]);
                if (number < 1 || number > 128) {
                    System.out.println("invalid IP");
                    return 0;
                }
                result = (int) (result + number * Math.pow(2, 8 * (3 - i)));
            } catch (NumberFormatException e) {
                System.out.println("invalid IP");
                return 0;
            }
        }
        System.out.println(result);
        return 0;
    }
}